﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bmz.Laboratory.DesignPattern
{
    class FactoryPattern
    {
        public interface Icar
        {
            void docar();
        }

        public class bwm : Icar
        {
            public void docar()
            {
                Console.WriteLine("我是宝马，别摸我");
            }
        }

        public class buick : Icar
        {
            public void docar()
            {
                Console.WriteLine("我是别克，很酷");
            }
        }


        public interface Icarfactory
        {
            Icar createCar();
        }

        public class bmwFactory : Icarfactory
        {
            public Icar createCar()
            {
                return new bwm();
            }
        }

        public class buickFactory : Icarfactory
        {
            public Icar createCar()
            {
                return new buick();
            }
        }


        public class test
        {
            public static void main(String[] args)
            {
                Icarfactory factory = new bmwFactory();
                Icar bwm = factory.createCar();
                bwm.docar();

                factory = new buickFactory();
                Icar buick = factory.createCar();
                buick.docar();

            }
        }
    }
}
